home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#48 (Sep 89)
/
Doodats ƒ
/
Doodat #2 Source
< prev
next >
Wrap
Text File
|
1989-06-12
|
2KB
|
111 lines
#define NIL 0L
/*
** Test a pointer for validity
*/
#define VALID_PTR(p) ((long)(p) && ((long)(p) & 1L) == NIL)
/*
** Test a handle for validity
*/
#define VALID_HNDL(h) (VALID_PTR(h) && VALID_PTR((long)(*(h)) & 0x00FFFFFF))
typedef struct
{
Handle hndl;
Rect frame;
unsigned char type;
unsigned char length;
short data[];
} ditl_list;
/*************************************************
**
** draw_ditl() - Lightspeed C Version
**
** This routine reads in and draws the items in a
** Dialog Item List (DITL) resource.
**
** In: resource id of DITL
**
** Out: N/A
**
*/
void
draw_ditl(ditl_id)
short ditl_id;
{
Handle ditl_h;
ditl_list *ditl_p;
PenState save_pen;
short d_type, offset, num_items;
ditl_h = GetResource('DITL', ditl_id);
if (ResError() != noErr || !VALID_HNDL(ditl_h))
return;
HLock(ditl_h);
/*
** don't change pen behind the window's back
*/
GetPenState(&save_pen);
PenNormal();
/*
** get the number of items in list
*/
num_items = *((short *)(*ditl_h)) + 1;
/*
** set pointer to first item in list
*/
ditl_p = (ditl_list *)((*ditl_h) + sizeof(short));
while (num_items--)
{
switch (ditl_p->type & 0x7F) /* mask out the item disabled bit */
{
case statText:
TextBox((char *)ditl_p->data, ditl_p->length, &(ditl_p->frame), teJustLeft);
break;
case iconItem:
ditl_p->hndl = GetIcon(ditl_p->data[0]);
if (VALID_HNDL(ditl_p->hndl))
{
PlotIcon(&(ditl_p->frame), ditl_p->hndl);
ReleaseResource(ditl_p->hndl);
}
break;
case picItem:
ditl_p->hndl = GetResource('PICT', ditl_p->data[0]);
if (VALID_HNDL(ditl_p->hndl))
{
DrawPicture((PicHandle)ditl_p->hndl, &(ditl_p->frame));
ReleaseReource(ditl_p->hndl);
}
break;
case userItem:
if (EmptyRect(&(ditl_p->frame)))
{
PenPat(gray);
MoveTo(ditl_p->frame.left, ditl_p->frame.top);
LineTo(ditl_p->frame.right, ditl_p->frame.bottom);
PenPat(black);
}
else
FrameRect(&(ditl_p->frame));
break;
}
/*
** force offset to a word (even) boundary
*/
if ((offset = ditl_p->length) & 1)
offset++;
/*
** advance pointer to next item
*/
ditl_p = (ditl_list *)((char *)ditl_p + sizeof(ditl_list) + offset);
}
HUnlock(ditl_h);
ReleaseResource(ditl_h);
/*
** restore pen to original condition
*/
SetPenState(&save_pen);
} /* end of draw_ditl() */